package com.github.tommas;

import java.util.Arrays;
import java.util.List;

public class GeneratorOptions {
    private final static String FernFlowerDecompiler = "fernflower";

    private final static String OPTION_SEP = ":";

    String outDir;

    List<String> classNameRegexs;

    String decompiler;

    List<String> packages;

    public static GeneratorOptions parse(String optionsStr) {
        GeneratorOptions options = new GeneratorOptions();
        options.outDir = "gen";

        if (optionsStr == null || optionsStr.isEmpty()) {
            return options;
        }

        for (String s : optionsStr.split(OPTION_SEP)) {
            String[] kv = s.split("=");
            if (kv.length != 2) {
                throw new RuntimeException(String.format("Invalid option: %s", s));
            }

            switch (kv[0]) {
                case "outDir":
                    options.outDir = kv[1];
                    break;
                case "classNameRegexs":
                    options.classNameRegexs = Arrays.asList(kv[1].split(","));
                    break;
                case "decompiler":
                    options.decompiler = kv[1];
                    break;
                case "packages":
                    options.packages = Arrays.asList(kv[1].split(","));
                    break;
                default:
                    throw new RuntimeException(String.format("Unknown option: %s", kv[0]));
            }
        }

        return options;
    }
}
